package com.intretech.umsin.common.exception;

import com.intretech.umsin.common.utils.MessageUtils;
import com.intretech.umsin.common.utils.StringUtils;


/**
 * @version V1.0
 * @ClassName: BusinessException
 * @Description: 功能描述 定义系统业务异常
 * @author: 李启联
 * @date: 2022-7-15 8:20
 * @Copyright: Copyright (c) 2022
 */
public class BusinessException extends RuntimeException{

    private static final long serialVersionUID = 1L;

    /**
     * 错误码,多语言环境下messages.properties配置文件对应的key
     */
    private String code;

    /**
     * 错误码对应的参数
     */
    private Object[] args;



    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Object[] getArgs() {
        return args;
    }

    public void setArgs(Object[] args) {
        this.args = args;
    }

    public BusinessException(String code, Object... args) {
        this.code = code;
        this.args = args;
    }


    @Override
    public String getMessage() {
        String message = null;
        if (!StringUtils.isEmpty(code)) {
            message = MessageUtils.message(code, args);
        }
        if (message  != null) {
            message = StringUtils.format(message,args);
        }
        return message;
    }



}